package com.icare.shop.server.alarm;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Bean;

import java.util.Timer;
import java.util.TimerTask;

/**
 * <pre>
 *    author  : tianhaibo
 *    email   : tianhaibo@jshuii.com
 *    time    : 2020/3/26   15:08
 *    desc    :
 *    version : v1.0
 * </pre>
 */
public class MemMonitorWechatAutoConfiguration {

    private static final Log log =  LogFactory.getLog(MemMonitorWechatAutoConfiguration.class);
    private static Runtime rt = Runtime.getRuntime();

    @Bean
    public Object initMemWechatMonitor(){
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                //监控内存，发邮件
                long l = rt.freeMemory() / 1024 / 1024;//MB
                log.info("当前剩余内存="+l+"MB，发微信报警");
            }
        },10*1000,5*1000);
        return new Object();
    }

}
